//
//  UIImage+Create.m
//  ITC_iOS
//
//  Created by iBenz on 2018/8/28.
//  Copyright © 2018年 Benz.L. All rights reserved.
//

#import "UIImage+Create.h"

@implementation UIImage(Create)
+ (UIImage *)imageWithColor:(UIColor *)color {
    return [UIImage imageWithColor:color size:(CGSize){1.0f, 1.0f}];
}

+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
    CGRect rect = CGRectZero;
    rect.size = size;
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

+ (UIImage *)imageWithGradients:(NSArray/*CGColorRef*/ *)colorRefs size:(CGSize)size {
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = (CGRect){CGPointZero, size};
    [gradientLayer setColors:colorRefs];
    [gradientLayer setStartPoint:CGPointMake(0.0, 0.0)];
    [gradientLayer setEndPoint:CGPointMake(1.0, 0.0)];
    
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);
    
    [gradientLayer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    return image;
}
@end
